package org.darkforest.task;

import org.darkforest.common.services.MessageAndNoticeService;
import org.darkforest.common.services.VoucherTemplateService;
import org.darkforest.dao.mapper.VoucherMapper;
import org.darkforest.model.Voucher;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * Created by abao on 2016/1/5.
 */
@Component
public class VoucherQuartz {

    private VoucherTemplateService voucherTemplateService;
    private VoucherMapper voucherMapper;
    private MessageAndNoticeService messageAndNoticeService;

    /****
     * 优惠券到期后设置为无效
     */
//    @Scheduled(cron = "0 0/10 * * * ?")
    public void cancelVoucher(){
        voucherTemplateService.voucherTask();
    }


    /****
     * 优惠券到期提醒
     */
//    @Scheduled(cron = "0 0/10 * * * ?")
    public void sendVoucherWillExpireToUser(){
        List<Voucher>  list= voucherMapper.selectWillExpire();
        for(Voucher voucher:list){
            messageAndNoticeService.sendVoucherWillExpireToUser(voucher);
        }
    }

}
